package com.yanqu.road.server.pb;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.activity.zhounianturntable.ZhouNianTurntableConfig;
import com.yanqu.road.entity.activity.zhounianturntable.ZhouNianTurntableData;
import com.yanqu.road.entity.activity.zhounianturntable.ZhouNianTurntableItem;
import com.yanqu.road.pb.activity.ZhouNianTurntableProto;
import com.yanqu.road.server.manger.activity.zhounianturntable.ZhouNianTurntableActivity;
import com.yanqu.road.server.manger.activity.zhounianturntable.ZhouNianTurntableMgr;

import java.util.Map;

public class ZhouNianTurntablePb {

    public static ZhouNianTurntableProto.TurntableSyncConfigRespMsg.Builder parseTurntableSyncConfigRespMsg() {
        ZhouNianTurntableProto.TurntableSyncConfigRespMsg.Builder builder = ZhouNianTurntableProto.TurntableSyncConfigRespMsg.newBuilder();
        for (Map.Entry<Integer, ZhouNianTurntableActivity> entry : ZhouNianTurntableMgr.activityMap.entrySet()) {
            ZhouNianTurntableProto.TurntableConfigMsg.Builder configMsg = ZhouNianTurntableProto.TurntableConfigMsg.newBuilder();
            configMsg.setActivityId(entry.getKey());
            for (ZhouNianTurntableConfig gearConfig : entry.getValue().configMap.values()) {
                ZhouNianTurntableProto.TurntableGearConfigMsg.Builder gearConfigMsg = ZhouNianTurntableProto.TurntableGearConfigMsg.newBuilder();
                gearConfigMsg.setGear(gearConfig.getGear());
                gearConfigMsg.setReward(gearConfig.getReward());
                gearConfigMsg.setSelectNum(gearConfig.getSelectNum());
                gearConfigMsg.setWeight(gearConfig.getWeight());
                gearConfigMsg.setAnnounce(gearConfig.getAnnounce());
                configMsg.addGearConfigList(gearConfigMsg);
            }
            builder.addConfigList(configMsg);
        }
        return builder;
    }

    public static ZhouNianTurntableProto.TurntableDataTemp.Builder createTurntableData(ZhouNianTurntableData userData) {
        ZhouNianTurntableProto.TurntableDataTemp.Builder builder = ZhouNianTurntableProto.TurntableDataTemp.newBuilder();
        for (ZhouNianTurntableItem userDataItem : userData.getItems()) {
            ZhouNianTurntableProto.TurntableItemTemp.Builder item = ZhouNianTurntableProto.TurntableItemTemp.newBuilder();
            item.setIndex(userDataItem.getIndex());
            item.setLeftDrawTimes(userDataItem.getLeftDrawTimes());
            item.setReward(userDataItem.getReward());
            item.setGear(userDataItem.getGear());
            builder.addItem(item);
        }
        builder.setChooseInfo(JSON.toJSONString(userData.getChooseInfoMap()));
        return builder;
    }

}
